import { _decorator, Component, Node, Vec3 } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('FollowTarget')
export class TargetFollow extends Component {

    @property(Node) 
    target: Node;  // 跟随目标

    @property(Vec3)
    offset: Vec3 = new Vec3(); // 跟随偏移

    start() {

    }

    tmpPos = new Vec3();

    update(deltaTime: number) {
        this.tmpPos = this.target.getPosition();  // 始终跟随目标位置移动
        this.tmpPos.add(this.offset);  // 增加偏移量

        this.node.position = this.tmpPos;
    }
}


